/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import BO.Controller;
import java.util.ArrayList;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Ymmot
 */
public class PrivatemessageBean {

    private ArrayList<PrivatemessageView> fromUsers;
    private ArrayList<PrivatemessageView> toUsers;
    private Controller controller;

    public PrivatemessageBean() {
        fromUsers = new ArrayList<PrivatemessageView>();
        toUsers = new ArrayList<PrivatemessageView>();
        controller = new Controller();
    }

    public ArrayList<PrivatemessageView> getFromUsers() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserView u = (UserView) session.getAttribute("user");
        fromUsers = controller.getPrivateMessagesReceivedByUserId(u.getId());
        return fromUsers;
    }

    public void setFromUsers(ArrayList<PrivatemessageView> fromUsers) {
        this.fromUsers = fromUsers;
    }

    public ArrayList<PrivatemessageView> getToUsers() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserView u = (UserView) session.getAttribute("user");
        toUsers = controller.getPrivateMessagesSentByUserId(u.getId());
        return toUsers;
    }

    public void setToUsers(ArrayList<PrivatemessageView> toUsers) {
        this.toUsers = toUsers;
    }
    
}
